/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachinesystem.tests;

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;
import junit.textui.TestRunner;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import warmachinesystem.ArmyList;
import warmachinesystem.BaseUnit;
import warmachinesystem.GameSystem;
import warmachinesystem.TRUnitType;
import warmachinesystem.UnitKind;
import warmachinesystem.WarmachineSystemFactory;
import warmachinesystem.WarmachineSystemPackage;

/**
 * <!-- begin-user-doc -->
 * A test case for the model object '<em><b>TR Unit Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following operations are tested:
 * <ul>
 *   <li>{@link warmachinesystem.TierRequirement#isMet(java.util.Map, warmachinesystem.ArmyList) <em>Is Met</em>}</li>
 * </ul>
 * </p>
 * @generated
 */
public class TRUnitTypeTest extends TestCase {

	private static final String GORGON = "scyrah08";
	private static final String DISCORDIA = "scyrah07";
	private static final String CHIMERA = "scyrah06";
	private static final String MAGE_HUNTER_ASSASSIN = "scyrah29";
	private static final String MAGE_HUNTER_STRIKE_FORCE = "scyrah19";
	/**
	 * The fixture for this TR Unit Type test case.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TRUnitType fixture = null;
	private GameSystem gs;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public static void main(String[] args) {
		TestRunner.run(TRUnitTypeTest.class);
	}

	/**
	 * Constructs a new TR Unit Type test case with the given name.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public TRUnitTypeTest(String name) {
		super(name);
		WarmachineSystemPackage.eINSTANCE.eClass();
		
		Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
		Map<String, Object> m = reg.getExtensionToFactoryMap();
//		m.put("wms", new WarmachineSystemResourceFactoryImpl());
		m.put("wms", new XMIResourceFactoryImpl());
		ResourceSet resSet = new ResourceSetImpl();
		URI gsUri = URI.createFileURI("../WarmachineSystem/gamesystem/System.wms");
		Resource res = resSet.getResource(gsUri, true);
		gs = (GameSystem) res.getContents().get(0);
	}

	/**
	 * Sets the fixture for this TR Unit Type test case.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected void setFixture(TRUnitType fixture) {
		this.fixture = fixture;
	}

	/**
	 * Returns the fixture for this TR Unit Type test case.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TRUnitType getFixture() {
		return fixture;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see junit.framework.TestCase#setUp()
	 * @generated
	 */
	@Override
	protected void setUp() throws Exception {
		setFixture(WarmachineSystemFactory.eINSTANCE.createTRUnitType());
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see junit.framework.TestCase#tearDown()
	 * @generated
	 */
	@Override
	protected void tearDown() throws Exception {
		setFixture(null);
	}

	/**
	 * Tests the '{@link warmachinesystem.TierRequirement#isMet(java.util.Map, warmachinesystem.ArmyList) <em>Is Met</em>}' operation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see warmachinesystem.TierRequirement#isMet(java.util.Map, warmachinesystem.ArmyList)
	 * @generated NOT
	 */
	public void testIsMet__Map_ArmyList() {
		Map<BaseUnit, Integer> map = getUnitMap(MAGE_HUNTER_STRIKE_FORCE);
		TRUnitType fix = getFixture();
		fix.setUnitType(getArmyList().getBaseUnitByCode(MAGE_HUNTER_STRIKE_FORCE));
		fix.setMin(1);
		assertTrue(fix.isMet(map, getArmyList()));
	}

	public void testIsMet__kind(){
		Map<BaseUnit, Integer> map = getUnitMap(MAGE_HUNTER_STRIKE_FORCE, MAGE_HUNTER_ASSASSIN);
		TRUnitType fix = getFixture();
		fix.setUnitTag("mage hunter");
		fix.setMin(3);
		assertTrue(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet__tag_koNumber(){
		Map<BaseUnit, Integer> map = getUnitMap(MAGE_HUNTER_STRIKE_FORCE, MAGE_HUNTER_ASSASSIN);
		TRUnitType fix = getFixture();
		fix.setUnitTag("mage hunter");
		fix.setMin(4);
		assertFalse(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet__tag_kotag(){
		Map<BaseUnit, Integer> map = getUnitMap(MAGE_HUNTER_STRIKE_FORCE, MAGE_HUNTER_ASSASSIN);
		TRUnitType fix = getFixture();
		fix.setUnitTag("light");
		fix.setMin(2);
		assertFalse(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet_kind(){
		Map<BaseUnit, Integer> map = getUnitMap(CHIMERA, DISCORDIA);
		TRUnitType fix = getFixture();
		fix.setUnitKind(UnitKind.WARJACK);
		fix.setMin(2);
		assertTrue(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet_kind_ko(){
		Map<BaseUnit, Integer> map = getUnitMap(CHIMERA, DISCORDIA);
		TRUnitType fix = getFixture();
		fix.setUnitKind(UnitKind.UNIT);
		fix.setMin(2);
		assertFalse(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet_kindTag(){
		Map<BaseUnit, Integer> map = getUnitMap(CHIMERA, GORGON);
		TRUnitType fix = getFixture();
		fix.setUnitKind(UnitKind.WARJACK);
		fix.setUnitTag("light");
		fix.setMin(2);
		assertTrue(fix.isMet(map, getArmyList()));
	}
	
	public void testIsMet_kindTag_ko(){
		Map<BaseUnit, Integer> map = getUnitMap(CHIMERA, DISCORDIA);
		TRUnitType fix = getFixture();
		fix.setUnitKind(UnitKind.WARJACK);
		fix.setUnitTag("heavy");
		fix.setMin(3);
		assertFalse(fix.isMet(map, getArmyList()));
	}

	protected ArmyList getArmyList(){
		return gs.getArmyByCode("scyrah");
	}
	protected Map <BaseUnit, Integer> getUnitMap(String... strings){
		HashMap<BaseUnit, Integer> result = new HashMap<BaseUnit, Integer>();
		int i = 1;
		for (String string : strings){
			BaseUnit bu = getArmyList().getBaseUnitByCode(string);
			result.put(bu, i);
			i++;
		}
		
		return result;
	}
} //TRUnitTypeTest
